﻿#include "Level1.h"
#include "IntroState.h"
#include "Utility.h"
#include "DotScene.h"

using namespace Ogre;

Level1 Level1::mLevel1;
SceneNode* worldNode;
CDotScene* myDotScene;

void Level1::enter()
{
	mRoot = Root::getSingletonPtr();

	mSceneMgr = mRoot->createSceneManager(ST_GENERIC);

	mSceneMgr->setAmbientLight( ColourValue( 1, 1, 1 ) );
	
	worldNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("worldRootNode");
	myDotScene = new CDotScene();
	myDotScene->parseDotScene("testScene.scene", "General", mSceneMgr, mSceneMgr->getSceneNode("worldRootNode"));

	mCamera = mSceneMgr->getCamera("Camera01");
	mViewport = mRoot->getAutoCreatedWindow()->addViewport(mCamera);
	mViewport->setBackgroundColour(ColourValue::Black);

	Ogre::Entity* ogrehead = mSceneMgr->createEntity("Ogre","Sphere01.mesh");
	Ogre::SceneNode* node = mSceneMgr->getSceneNode("Sphere01");
	node->attachObject(ogrehead);
	
	Utility::drawTxt("OgName","ñ, ~, €, $&#273;&#x111;", node);
	
	mExitGame = false;
}

void Level1::exit()
{
	mSceneMgr->clearScene();
	mRoot->getAutoCreatedWindow()->removeAllViewports();
}

void Level1::pause()
{
}

void Level1::resume()
{
}

bool Level1::frameStarted(const FrameEvent& evt)
{
	return true;
}

bool Level1::frameEnded(const FrameEvent& evt)
{
	if (mExitGame)
		return false;

	return true;
}

void Level1::keyPressed( const OIS::KeyEvent &e ) {
}

void Level1::keyReleased( const OIS::KeyEvent &e ) {
    if( e.key == OIS::KC_ESCAPE ) {

        mExitGame = true;
    }
	if( e.key == OIS::KC_RETURN ) {

		changeState(IntroState::getInstance());
    }
}

void Level1::mouseMoved( const OIS::MouseEvent &e ) {
}

void Level1::mousePressed( const OIS::MouseEvent &e, OIS::MouseButtonID id ) {
}

void Level1::mouseReleased( const OIS::MouseEvent &e, OIS::MouseButtonID id ) {
    
}